package com.campus.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.campus.mapper.ChatMessageMapper;
import com.campus.pojos.domain.ChatMessage;
import com.campus.service.ChatMessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ChatMessageServiceImpl extends ServiceImpl<ChatMessageMapper, ChatMessage> implements ChatMessageService {

    public void setChatMessageMapper(ChatMessageMapper chatMessageMapper) {
        this.chatMessageMapper = chatMessageMapper;
    }

    public ChatMessageMapper getChatMessageMapper() {
        return chatMessageMapper;
    }

    @Autowired
    ChatMessageMapper chatMessageMapper;
    /**
     * 获取聊天内容
     * @param fromUserId
     * @param toUserId
     * @return
     */
    @Override
    public List<ChatMessage> getMessage(Integer fromUserId, Integer toUserId) {
        //List<ChatMessage> messages = chatMessageMapper.getByFromUserIdAndToUserId(fromUserId,toUserId);

        QueryWrapper<ChatMessage> qw  = new QueryWrapper<>();

        qw.in("from_user_id", fromUserId,toUserId);
        qw.in("to_user_id", toUserId,fromUserId);
        qw.orderByAsc("send_time");
        return list(qw);

    }

    @Override
    public ChatMessage getById(Long id) {
        return getById(id);
    }
}
